<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任务名称" prop="taskName">
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单名称" prop="workOrderName">
        <el-input
          v-model="queryParams.workOrderName"
          placeholder="请输入工单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="workOrderStauts">
        <el-select v-model="queryParams.workOrderStauts" placeholder="请选择工单状态">
          <el-option
            v-for="dict in workOrderStautsS"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zndd:solution:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['zndd:solution:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['zndd:solution:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zndd:solution:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="znddList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"></el-table-column>
      <!--      <el-table-column label="序号" align="center" width="130" prop="row"/>-->
      <!--      <el-table-column label="主键" align="center" width="50" prop="id" />-->
<!--      <el-table-column label="部门id" align="center" prop="deptId" />-->
      <el-table-column label="任务名称" align="center" width="200" prop="taskName" />
      <el-table-column label="工单名称" align="center" width="200" prop="workOrderName" show-overflow-tooltip/>
      <el-table-column label="工单号" align="center" width="200" prop="workOrderNo" show-overflow-tooltip/>
      <el-table-column label="工单状态" align="center" width="130" prop="workOrderStauts" :formatter="solutionFormatter"/>
      <el-table-column label="车辆顺序" align="center" width="130" prop="carOrder" />
      <el-table-column label="解决方案" align="center" width="500" prop="solutionDescribe" show-overflow-tooltip/>
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip/>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['zndd:solution:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['zndd:solution:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改解决方案信息对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="任务id" prop="taskId">
          <el-input v-model="form.taskId" placeholder="请输入任务id" />
        </el-form-item>
        <el-form-item label="工单id" prop="workOrderId">
          <el-input v-model="form.workOrderId" placeholder="请输入工单id" />
        </el-form-item>
        <el-form-item label="车辆顺序" prop="carOrder">
          <el-input v-model="form.carOrder" placeholder="请输入车辆顺序" />
        </el-form-item>
        <el-form-item label="解决方案说明" prop="solutionDescribe">
          <el-input v-model="form.solutionDescribe" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listZndd, getZndd, delZndd, addZndd, updateZndd } from "@/api/zndd/solution/solution";

export default {
  name: "Zndd",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //问题类型数据
      workOrderStautsS:[],
      // 解决方案信息表格数据
      znddList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // deptId: null,
        // taskId: null,
        // workOrderId: null,
        taskName: undefined,
        workOrderName: undefined,
        workOrderNo: null,
        workOrderStauts: null,
        carOrder: null,
        // solutionDescribe: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
        taskId: [
          { required: true, message: "任务id不能为空", trigger: "blur" }
        ],
        workOrderId: [
          { required: true, message: "工单id不能为空", trigger: "blur" }
        ],
        carOrder: [
          { required: true, message: "车辆顺序不能为空", trigger: "blur" }
        ],
        solutionDescribe: [
          { required: true, message: "解决方案说明不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    //获取字典表中产线类型
    this.getDicts("zndd_worker_order_status").then(response => {
      this.workOrderStautsS = response.data;
    });
    this.getList();
  },
  methods: {
    //格式化问题类型
    solutionFormatter(row, column) {
      const workOrderStatus = this.workOrderStautsS.find(workOrderStauts => workOrderStauts.dictValue === row.workOrderStauts);
      return workOrderStatus ? workOrderStatus.dictLabel : '';
    },
    /** 序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if (pageNum !== -1 && pageNum !== 0) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return index + 1;
      }
    },
    /** 查询解决方案信息列表 */
    getList() {
      this.loading = true;
      listZndd(this.queryParams).then(response => {
        this.znddList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        // id: null,
        // deptId: null,
        // taskId: null,
        // workOrderId: null,
        // carOrder: null,
        taskName: null,
        workOrderName: null,
        workOrderNo: null,
        workOrderStauts: null,
        solutionDescribe: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加解决方案信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZndd(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改解决方案信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZndd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZndd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除解决方案信息编号为"' + ids + '"的数据项？').then(function() {
        return delZndd(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zndd/zndd/export', {
        ...this.queryParams
      }, `zndd_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
